-
Notifications
You must be signed in to change notification settings - Fork 292
Make 'mini.files' default explorer work with 'mini.pick' #2157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make 'mini.files' default explorer work with 'mini.pick' #2157
Conversation
|
Thanks for the PR! Although this technically fixes the #2156, I'd ask if you want to find the culprit here. As this is very strange to expect errors after explicitly checking that Writing a test case would possible make this easier. My guess is that this has to do with 'mini.files' being default explorer. |
|
Yes, without mini.files the problem does not occur. My guess is that mini.files is "in progress", creating or refreshing its buffers. I just don't understand why it doesn't happen when mini.starter is visible. I will look into it. |
|
I modified mini.files a little to prevent an explicit H.track_dir_edit = function(data)
-- Make early returns
if vim.api.nvim_get_current_buf() ~= data.buf then return end
if vim.b.minifiles_processed_dir then
-- Smartly delete directory buffer if already visited
local alt_buf = vim.fn.bufnr('#')
if alt_buf ~= data.buf and vim.fn.buflisted(alt_buf) == 1 then vim.api.nvim_win_set_buf(0, alt_buf) end
return -- COMMENTED return vim.api.nvim_buf_delete(data.buf, { force = true })
end
local path = vim.api.nvim_buf_get_name(0)
if vim.fn.isdirectory(path) ~= 1 then return end
-- Make directory buffer disappear when it is not needed
vim.bo.bufhidden = 'wipe'
vim.b.minifiles_processed_dir = true
-- Open directory without history
vim.schedule(function() MiniFiles.open(path, false) end)
endI added some print statements. The scenario: Open nvim with init.lua, press mini.files in track dir for data.buf 1
mini.files in track dir, no early return
mini.files in track dir, return, not a directory /home/user/.config/repro/init.lua
mini.pick in default chose
mini.files in track dir for data.buf 3
mini.files in track dir, no early return
mini.files still in track dir, marking vim.b.minifiles_processed_dir
mini.pick advance before stop -- NOTE: mini.files does not yet appear....
mini.pick set curwin
mini.files in track dir for data.buf 3
mini.files in track dir, no early return
mini.files in track dir, has vim.b.minifiles_processed_dir, alt buf is 1
---
--- Without modification, crashes here...
---
--- Happy path:
mini.files in track dir for data.buf 4
mini.files in track dir, no early return
mini.files in track dir, return, not a directory minifiles://4//home/user/.config/reproThe So, the fix could also be in mini.files, by not deleting the buffer and just return instead. Perhaps the explicit delete is not necessary anyways, because of I think its best to fix in mini.files, to not crash on an external |
The buffer deleting is for the following use case:
It is probably not a big deal and a rare use case, but at least trying to account for that is reasonable. And, of course, needs tests both here and 'mini.extra'. |
ff224a3 to
dca9884
Compare
|
I unfortunately cannot reproduce the buffer deleting scenario you described. Testing with Still todo: A test in mini.extra |
|
Yes, that clarifies..) |
|
@abeldekat, couple of quick notes before I'll get to this tomorrow:
|
I am trying to test for the presence of errors. Unfortunately, vim.v.errmsg is empty. The expect_screenshot does show the error situation, whereby the picker is not closed. However, the error text that pops up in a real session is not shown. After the fix, the expect_screenshot shows the correct situation: picker closed, files open... |
echasnovski
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've left general suggestions about how each test could be improved. However, they already look very reasonable. Thank you, nice job 👍
No need to apply these changes, as I'd like to take the opportunity to adjust some existing tests. Will follow up on the final result.
| -- Starting with empty buffer having id 1 | ||
| child.cmd('edit ' .. test_dir_path) | ||
| close() | ||
|
|
||
| local bufs = child.api.nvim_list_bufs() | ||
| eq(#bufs, 1) | ||
|
|
||
| -- Assert that buffer with id 1 has been deleted, otherwise it would be named to directory test_dir_path | ||
| local is_still_one = bufs[1] == 1 | ||
| eq(is_still_one, false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Using explicit buffer ids is usually a bad idea. It can fail if there is some change in how initial state of the child process is done.
- If you want to check that the name is not for the directory, then should do so more directly.
- There is no need to check if the initial buffer was deleted, since this is not the goal (more like a side effect).
| -- Starting with empty buffer having id 1 | |
| child.cmd('edit ' .. test_dir_path) | |
| close() | |
| local bufs = child.api.nvim_list_bufs() | |
| eq(#bufs, 1) | |
| -- Assert that buffer with id 1 has been deleted, otherwise it would be named to directory test_dir_path | |
| local is_still_one = bufs[1] == 1 | |
| eq(is_still_one, false) | |
| local buf_name_init = child.api.nvim_buf_get_name(0) | |
| child.cmd('edit ' .. test_dir_path) | |
| close() | |
| -- Should not leave buffer named after opened directory | |
| eq(child.api.nvim_buf_get_name(0), buf_name_init) | |
| eq(#child.api.nvim_list_bufs(), 1) |
| -- Starting with listed buffer having id 1 | ||
| child.cmd('edit ' .. test_file_path) | ||
| child.cmd('edit ' .. test_dir_path) | ||
| close() | ||
|
|
||
| local bufs = child.api.nvim_list_bufs() | ||
| eq(#bufs, 1) | ||
| eq(bufs[1], 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar notes about using explicit buffer ids. Although I think this test might be redundant as there is already the other "handles close without opening file".
| -- Starting with listed buffer having id 1 | |
| child.cmd('edit ' .. test_file_path) | |
| child.cmd('edit ' .. test_dir_path) | |
| close() | |
| local bufs = child.api.nvim_list_bufs() | |
| eq(#bufs, 1) | |
| eq(bufs[1], 1) | |
| local buf_id_init = child.api.nvim_get_current_buf() | |
| child.cmd('edit ' .. test_file_path) | |
| child.cmd('edit ' .. test_dir_path) | |
| close() | |
| eq(child.api.nvim_list_bufs(), { buf_id_init }) |
| child.cmd('edit ' .. test_file_path) | ||
| child.cmd('edit ' .. test_dir_path) | ||
| child.lua([[ | ||
| local win_id = vim.api.nvim_list_wins()[1] -- win id 1000 | ||
| vim.api.nvim_set_current_win(win_id) | ||
| ]]) | ||
| child.expect_screenshot() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
There rarely should be need to use
child.lua('vim.api.nvim_xxx()')approach. Usually if it involves data structures that can not be transmitted between test runner and child instances. Usually it involves functions anduserdatatypes (likelibuvtimers, tree-sitter nodes, etc.).Whenever possible, use
child.api.nvim_xxx()directly.
| child.cmd('edit ' .. test_file_path) | |
| child.cmd('edit ' .. test_dir_path) | |
| child.lua([[ | |
| local win_id = vim.api.nvim_list_wins()[1] -- win id 1000 | |
| vim.api.nvim_set_current_win(win_id) | |
| ]]) | |
| child.expect_screenshot() | |
| child.cmd('edit ' .. test_file_path) | |
| child.cmd('edit ' .. test_dir_path) | |
| local win_id = child.api.nvim_list_wins()[1] | |
| child.api.nvim_set_current_win(win_id) | |
| child.expect_screenshot() |
Usually a test for error is But the 'test_extra.lua' should test for absence of errors. Which is |
| @@ -0,0 +1,33 @@ | |||
| --|---------|---------|---------|---------| | |||
| 01|┌…s/mini.nvim/tests/dir-extra/real-file┐ | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test fails since it clips the final s in what seems to be your local directory where 'mini.nvim' is located. The GitHub runner (and possibly other local runs) will probably have different letter here.
This is the drawback of using screenshot testing. The "mock window title" approach could have also been more robust here, but if there is a reasonably concise way to not do a screenshot testing, it should usually be taken.
|
Thanks again for the PR! I'll merge in temporary branch and adjust some things. |
|
The variation of this should now be on latest The big difference (from my earlier comments as well) is that it seemed like a good idea to check 'mini.pick' directly that it works when choosing the directory path. And not one picker in 'mini.extra'. The actual 'mini.pick' testing approach also isn't exactly super robust or clean (screenshot might have been better), but seems good enough: it breaks without this PR's code change and passes otherwise. |
Great! Thank you, also for the advice in the review. Regarding the original test in test_extra, I did know to test for |
Yeah, the error that is present when run interactively did not propagate for some reason. That's why I had to resort to counting floating windows instead. |
Fixes: #2156
I think it's a timing problem, as the error does not occur when the starter is visible.
It's very strange though: The window is valid. I tested that even the buffer is valid. Still,
nvim_set_current_wincrashes.